package impl

import (
	"adam2/internal/model"
	"anubis-framework/pkg/io"
)

type CommodityFutureHourDataDaoImpl struct {
	*BaseDaoImpl
}

// 返回dao实现类
func GetCommodityFutureHourDataDaoImpl() *CommodityFutureHourDataDaoImpl {
	return &CommodityFutureHourDataDaoImpl{GetBaseDaoImpl()}
}

// 返回表名
func (_commodityFutureHourDataDaoImpl *CommodityFutureHourDataDaoImpl) FindTableName() string {
	return "COMMODITY_FUTURE_HOUR_DATA"
}

// 根据code、开始时间和结束时间查询记录
func (_commodityFutureHourDataDaoImpl *CommodityFutureHourDataDaoImpl) FindByCodeBetweenDate(code string, beginDate string, endDate string) model.CommodityFutureHourDataArray {
	io.Infoln("根据code[%s]、开始时间[%s]和结束时间[%s]查询记录", code, beginDate, endDate)

	var commodityFutureHourDataArray model.CommodityFutureHourDataArray
	_commodityFutureHourDataDaoImpl.db.Raw("select * from commodity_future_hour_data t "+
		"where t.code=? and t.end_time between to_date(?, 'yyyy-mm-dd') and to_date(?, 'yyyy-mm-dd') "+
		"order by t.end_time asc",
		code, beginDate, endDate).Find(&commodityFutureHourDataArray)
	return commodityFutureHourDataArray
}
